<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'defaultRoute' => 'auth/login', 
    'language' => 'ru',
    'name' => 'Weather',
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 's1ekFueS7E9AlLB4qP7npIEXa-wZ8Ffo',
            'baseUrl' => '',
            'enableCsrfValidation' => false,
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'mailer' => [
            'class' => \yii\symfonymailer\Mailer::class,
            'viewPath' => '@app/mail',
            // send all mails to a file by default.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => [
                // Auth
                'login' => 'auth/login',
                'logout' => 'auth/logout',
                'registration' => 'auth/registration',
                // Account
                'accounts/<accountId:\d+>' => 'accounts/view',
                'accounts/search' => 'accounts/search',
                'PUT accounts/<accountId:\d+>' => 'accounts/update',
                'DELETE accounts/<accountId:\d+>' => 'accounts/delete',
                // Region
                'region/<regionId:\d+>' => 'region/view',
                'region/' => 'region/create',
                'region/<regionId:\d+>/weather/<weatherId:\d+>' => 'region/create-weather',
                'PUT region/<regionId:\d+>' => 'region/update',
                'DELETE region/<regionId:\d+>' => 'region/delete',
                'DELETE region/<regionId:\d+>/weather/<weatherId:\d+>' => 'region/delete-weather',
                // Region type
                'region/types/<typeId:\d+>' => 'region-types/view',
                'region/types' => 'region-types/create',
                'PUT region-types/<typeId:\d+>' => 'region-types/update',
                'DELETE region-types/<typeId:\d+>' => 'region-types/delete',
                // Weather
                'region/weather/<regionId:\d+>' => 'weather/view',
                'region/weather/search' => 'weather/search',
                'region/weather' => 'weather/create',
                'PUT region-weather/<regionId:\d+>' => 'weather/update',
                'DELETE region-weather/<regionId:\d+>' => 'weather/delete',
                // Forecast
                'region/weather/forecast/<forecastId:\d+>' => 'forecast/view',
                'PUT region/weather/forecast/<forecastId:\d+>' => 'forecast/update',
                'region/weather/forecast' => 'forecast/create',
                'DELETE region/weather/forecast/<forecastId:\d+>' => 'forecast/delete',
            ],
        ],
    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];
}

return $config;